<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增背景音乐')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-incidentalmusic-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('incidental_music_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">权重(越大排越前)：</label>
                <div class="col-sm-8">
                    <input name="weight" class="form-control" type="text" value="1">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否发布：</label>
                <div class="col-sm-8">
                    <select name="status" class="form-control m-b" th:with="type=${@dict.getType('common_status')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">音频：</label>
                <div class="col-sm-8">
                    <input id="audioUrl" name="audioUrl" type="hidden">
                    <input id="file" name="file" type="file" class="file" data-show-preview="true"  data-show-caption="false"  data-show-upload="false" data-show-close="false">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
        var prefix = ctx + "poem/incidentalmusic"
        $("#form-incidentalmusic-add").validate({
            focusCleanup: true
        });

        var allowedFileExtensions = ["mp3"];
		var dropZoneTitle = "支持mp3";

		$("#file").fileinput({
            'uploadUrl': '/common/uploadOSS?prefix=incidental',
            'dropZoneTitle': dropZoneTitle,
            'allowedFileExtensions': allowedFileExtensions
        }).on("fileuploaded", function(e, data, previewiId, index){
        	 $('#audioUrl').val(data.response.url);
        }).on("filebatchselected", function(event, files) {
            $(this).fileinput("upload");
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-incidentalmusic-add').serialize());
            }
        }

    </script>
</body>
</html>